package com.yunxiu.controller;

import com.yunxiu.entity.LogInfo;
import com.yunxiu.service.LogInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 *登入mvc
 * @author Deom
 */
@Controller
@RequestMapping("/LoginInfo")
public class LogInfoController {
    @Autowired
    private LogInfoService logInfoService;

    /**
     * 显示所有的日志信息
     * @return
     */
    @RequestMapping(value = "/myLogInfo.do")
    public String myLogInfo(HttpServletRequest request,HttpServletResponse response) {
        List<LogInfo> logInfos=logInfoService.listLogInf();
        request.setAttribute("listLogInf",logInfos);
        return "myloginfo";
    }
    /**
     * 批量删除日志
     */
    @RequestMapping(value = "/deleteMapLogInfo")
    public String deleteMapLogInfo(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        //标记是否删除
        int row=0;
        try{
            String[] checked1s = request.getParameterValues("checked1");
            if (checked1s!=null&&!checked1s.equals("")){
                for (String checked1 : checked1s) {
                    System.out.println(checked1);
                }
                row=logInfoService.deleteMapOperator(checked1s);
            }else{
                out.print("<script>alert('至少选中一个');location.href='/LoginInfo/myLogInfo.do';</script>");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return "/LoginInfo/myLogInfo.do";
    }
}
